/**
 * 树形结构遍历
 * @param {Array} tree 树形结构数据
 * @param {Function} callback 回调函数如果返回真，停止遍历
 */
export function eachTree(tree, cb) {
  for (let i = 0; i < tree.length; i++) {
    let item = tree[i]
    let result

    if (cb) result = cb(item)

    if (!result) result = eachTree(item.children, cb)

    if (result) return result
  }
}
